package com.ruoyi.project.zxcrm.controller;


import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.zxcrm.domain.CrmSmsTemplate;
import com.ruoyi.project.zxcrm.service.ICrmSmsTemplateService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 信息模板Controller
 *
 * @author mn
 * @date 2023-02-23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/crm/template")
public class CrmSmsTemplateController extends BaseController {

    private final ICrmSmsTemplateService crmSmsTemplateService;

    /**
     * 查询信息模板列表
     */
    @PreAuthorize("@ss.hasPermi('crm:template:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<CrmSmsTemplate> list = crmSmsTemplateService.selectCrmSmsTemplateList();
        return getDataTable(list);
    }

    /**
     * 导出信息模板列表
     */
    @PreAuthorize("@ss.hasPermi('crm:template:export')")
    @Log(title = "信息模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        List<CrmSmsTemplate> list = crmSmsTemplateService.selectCrmSmsTemplateList();
        ExcelUtil<CrmSmsTemplate> util = new ExcelUtil<CrmSmsTemplate>(CrmSmsTemplate.class);
        util.exportExcel(response, list, "信息模板数据");
    }

    /**
     * 获取信息模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crmSmsTemplateService.selectCrmSmsTemplateById(id));
    }

    //    /**
//     * 新增信息模板
//     */
    @PreAuthorize("@ss.hasPermi('crm:template:add')")
    @Log(title = "信息模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmSmsTemplate crmSmsTemplate) {
        return toAjax(crmSmsTemplateService.insertCrmSmsTemplate(crmSmsTemplate));
    }

    /**
     * 修改信息模板
     */
    @PreAuthorize("@ss.hasPermi('crm:template:edit')")
    @Log(title = "信息模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmSmsTemplate crmSmsTemplate) {
        return toAjax(crmSmsTemplateService.updateCrmSmsTemplate(crmSmsTemplate));
    }



}
